﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars;
using KTX.Public;
using KTX.BLL;

namespace KTX.Giaodien
{
    public partial class FrmMain : DevExpress.XtraEditors.XtraForm
    {
        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static Session _sss = new Session();
        public static string _User;
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            bbiDangnhap_ItemClick(sender, null);
        }

        private void bbiDangnhap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (bbiDangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                bbiDangnhap.Caption = STR_LOGIN;

                bbiDongtatca_ItemClick(sender, e);
            }

            Login.FrmLogin x = new Login.FrmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = _sss.Name;
                _User = _sss.Acc;
                bbiDangnhap.Caption = STR_LOGOUT;
                
                rpDanhmuc.Visible = true;
                rpNghiepvu.Visible = true;
                rpgNguoidung.Visible = true;                
                bbiDoimatkhau.Visibility = BarItemVisibility.Always;
            }
            else
            {
                rpDanhmuc.Visible = false;
                rpNghiepvu.Visible = false;
                rpgNguoidung.Visible = false;                          
                bbiDoimatkhau.Visibility = BarItemVisibility.Never;
            }

            //EnableMenu();
        }

        

        private void bbiDongtatca_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();      
        }

        private void bbiThoat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void bbiDoimatkhau_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Login.FrmChangePass frm = new Login.FrmChangePass();
            frm._User = _User;
            frm.ShowDialog();
        }

        private void bbiThanhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is FrmCanbo) return;
            var frm = new FrmCanbo() { MdiParent = this };
            frm.Show();
        }
     

       
    }
}